package system.company.actor.Ordinary_Staff;

import java.util.List;



import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Transaction;
import org.hibernate.criterion.Example;

/**
 * A data access object (DAO) providing persistence and search support for
 * Ordinary_Staff entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see system.company.actor.Ordinary_Staff.Ordinary_Staff
 * @author MyEclipse Persistence Tools
 */

public class Ordinary_StaffDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(Ordinary_StaffDAO.class);
	// property constants
	public static final String NAME = "name";
	public static final String PASSWORD = "password";
	public static final String STATUS = "status";
	public static final String DEPARTMENT = "department";

	public void save(Ordinary_Staff transientInstance) {
		log.debug("saving Ordinary_Staff instance");
		try {
			Transaction tran = getSession().getTransaction();
			tran.begin();

			getSession().save(transientInstance);
			tran.commit();
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Ordinary_Staff persistentInstance) {
		log.debug("deleting Ordinary_Staff instance");
		try {
			Transaction tran = getSession().getTransaction();
			tran.begin();
			getSession().delete(persistentInstance);
			tran.commit();
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Ordinary_Staff findById(java.lang.String id) {
		log.debug("getting Ordinary_Staff instance with id: " + id);
		try {
			Ordinary_Staff instance = (Ordinary_Staff) getSession().get(
					"system.company.actor.Ordinary_Staff.Ordinary_Staff", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Ordinary_Staff instance) {
		log.debug("finding Ordinary_Staff instance by example");
		try {
			List results = getSession().createCriteria(
					"system.company.actor.Ordinary_Staff.Ordinary_Staff").add(
					Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Ordinary_Staff instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from Ordinary_Staff as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByName(Object name) {
		return findByProperty(NAME, name);
	}

	public List findByPassword(Object password) {
		return findByProperty(PASSWORD, password);
	}

	public List findByStatus(Object status) {
		return findByProperty(STATUS, status);
	}

	public List findByDepartment(Object department) {
		return findByProperty(DEPARTMENT, department);
	}

	public List findAll() {
		log.debug("finding all Ordinary_Staff instances");
		try {
			String queryString = "from Ordinary_Staff";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Ordinary_Staff merge(Ordinary_Staff detachedInstance) {
		log.debug("merging Ordinary_Staff instance");
		try {
			Ordinary_Staff result = (Ordinary_Staff) getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Ordinary_Staff instance) {
		log.debug("attaching dirty Ordinary_Staff instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Ordinary_Staff instance) {
		log.debug("attaching clean Ordinary_Staff instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}